package com.sxpi.order.mode.user;

import com.sxpi.order.mode.user.member.NormalVipService;
import com.sxpi.order.mode.user.member.SVipService;
import com.sxpi.order.mode.user.member.VipService;
import com.sxpi.order.mode.user.member.YearVipService;
import org.springframework.context.ApplicationContextAware;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @Author: 董伟豪
 * @Date: 2022/10/29 22:31
 */
public class UserBeanFactory{

    /**
     * 简单工厂设计模式
     * 但是这样的方式没有必要，因为每次来一个用户我都需要new一个对象，内存太大
     * @param vip
     * @return
     */
    public static IPayService getInstance(Integer vip){
        if(vip.equals(1)){
            return new NormalVipService();
        }else if(vip.equals(2)){
            return new VipService();
        }else if(vip.equals(3)){
            return new SVipService();
        }
        return null;
    }


    /**
     * springIOC注册表的方式
     */
    public static Map<Integer,IPayService> map = new ConcurrentHashMap<>();
    static {
        map.put(1,new NormalVipService());
        map.put(2,new VipService());
        map.put(3,new SVipService());
        map.put(4,new YearVipService());
    }
    public static IPayService getInstanceByMap(Integer vip){
        return map.get(vip);
    }


}
